<?php
header("Content-Type:application/json;charset=utf-8");
require("../init.php");
//sql
$sql = " SELECT * FROM dk_book";
@$kw = $_REQUEST["kw"];
if($kw != null){
    $kws = explode(" ", $kw);   //相当于js中的split   Var kws = kw.split(" ");
    //kws = [刘慈欣 , 三体, 小说]
    for($i = 0; $i < count($kws); $i++){
        $kws[$i] = " title Like '%$kws[$i]%' ";
    }//kws = [title LIKE %刘慈欣%, title LIKE %三体%, title LIKE %小说% ...]
    $where = implode(" AND ", $kws); //相当于js中的join var where = kws.join(" AND ");
    $sql .=" where $where ";
}
$result = mysqli_query($conn,$sql);
if(mysqli_error($conn)){
    echo mysqli_error($conn);
}
$rows=mysqli_fetch_all($result,1);
@$pno=$_REQUEST["pno"];
if($pno==null) $pno=1;
$psize=9;
$count=count($rows);
$sql.=" limit ".(($pno-1)*$psize).",$psize";
$result=mysqli_query($conn,$sql);
$rows=mysqli_fetch_all($result,1);
$output=[
	"pno"=>$pno,
	"psize"=>$psize,
	"count"=>$count,
	"pcount"=>ceil($count/$psize),
	"data"=>$rows
];
echo json_encode($output);
?>